//
//  XXAlert.swift
//  aquariumstudio
//
//  Created by zj on 2022/10/15.
//  Copyright © 2022 LXF. All rights reserved.
//

import Foundation
import FastComponent
import UIKit

public struct XXAlert {
    
    public  static func showErrorAlert(on vc: UIViewController, message: String?, actions: [UIAlertAction] = [UIAlertAction(title: "OK".i18n, style: .default)], sourceView:UIView? = nil){
        showBasicAlert(on: vc, with: "Error".i18n, message: message ?? "", actions: actions,sourceView: sourceView)
    }
    
    public static func showBasicAlert(on vc: UIViewController, with title: String, message: String, actions: [UIAlertAction] = [UIAlertAction(title: "OK".i18n, style: .default)], sourceView:UIView? = nil) {
        let alertVC = UIAlertController(title: title, message: message, preferredStyle: .alert)
        
        for action in actions {
            alertVC.addAction(action)
        }
        
        DispatchQueue.main.async { 
            if let sourceView = sourceView {
                vc.present(alertVC: alertVC, sourceView: sourceView)
            }else{
                vc.present(alertVC: alertVC, sourceView: vc.view)
            }
        }
    }
}
